#!/bin/bash

export PATH=$PATH:${HOME}/install/jdk1.5.0_04/bin:${HOME}/install/apache-tomcat-5.5.15/bin/:${HOME}/install/mysql-max-5.0.18-linux-i686/bin/
export JAVA_HOME=${HOME}/install/jdk1.5.0_04/
export CLASSPATH=${HOME}/install/jdk1.5.0_04/lib/tools.jar

BIND_ETH=eth1

JAVA_EXE=${JAVA_HOME}/bin/java
RREG_EXE=${JAVA_HOME}/bin/rmiregistry
#BIND_IP=`/sbin/ifconfig ${BIND_ETH} | grep "inet " | awk -F" " '{ print $2; }' | awk -F":" '{ print $2; }'`
BIND_IP=192.168.1.30
BIND_PORT=1099

ISSO_RMI_PORT=2099

PROVISION_DIR=${HOME}/install/provisioning
#ISSO_PROVISION_DIR=${HOME}/install/provisioning/ISSO

ICONTACT_RMI_PORT=3099
#ICONTACT_PROVISION_DIR=${HOME}/install/provisioning/IContact

ILINK_RMI_PORT=4099
#ILINK_PROVISION_DIR=${HOME}/install/provisioning/ILink

case "$1" in
    start)
	cd ${PROVISION_DIR}
	${RREG_EXE} -J-classpath -J"." &
	sleep 3
	${JAVA_EXE} -Djava.rmi.server.codebase=file:///./ -cp "${CLASSPATH}:.:./conf:./issoMappings/:./lib/mysql-connector-java-3.1.10-bin.jar:./lib/log4j-1.2.9.jar:./lib/asm.jar:./lib/hibernate3.jar:./lib/antlr.jar:./lib/asm-attrs.jar:./lib/cglib-2.1.3.jar:./lib/commons-collections.jar:./lib/commons-logging.jar:./lib/dom4j-1.6.1.jar:./lib/jta.jar:./lib/mail.jar:./lib/activation.jar:./lib/commons-dbcp-1.2.1.jar:./lib/commons-pool-1.3.jar" net.amsoft.iservice.asp.provisioning.server.isso.ISSOServer rmi://${BIND_IP}:${BIND_PORT}/ISSOServer ${ISSO_RMI_PORT} &
	sleep 3
	cd ${PROVISION_DIR}
	${JAVA_EXE} -Djava.rmi.server.codebase=file:///./ -cp "${CLASSPATH}:.:./conf:./icontactMappings/:./lib/mysql-connector-java-3.1.10-bin.jar:./lib/log4j-1.2.9.jar:./lib/asm.jar:./lib/hibernate3.jar:./lib/antlr.jar:./lib/asm-attrs.jar:./lib/cglib-2.1.3.jar:./lib/commons-collections.jar:./lib/commons-logging.jar:./lib/dom4j-1.6.1.jar:./lib/jta.jar:./lib/mail.jar:./lib/activation.jar:./lib/commons-dbcp-1.2.1.jar:./lib/commons-pool-1.3.jar" net.amsoft.iservice.asp.provisioning.server.icontact.IContactServer rmi://${BIND_IP}:${BIND_PORT}/IContactServer ${ICONTACT_RMI_PORT} &
	sleep 3
	cd ${PROVISION_DIR}
	${JAVA_EXE} -Djava.rmi.server.codebase=file:///./ -cp "${CLASSPATH}:.:./conf:./ilinkMappings/:./lib/mysql-connector-java-3.1.10-bin.jar:./lib/log4j-1.2.9.jar:./lib/asm.jar:./lib/hibernate3.jar:./lib/antlr.jar:./lib/asm-attrs.jar:./lib/cglib-2.1.3.jar:./lib/commons-collections.jar:./lib/commons-logging.jar:./lib/dom4j-1.6.1.jar:./lib/jta.jar:./lib/mail.jar:./lib/activation.jar:./lib/commons-dbcp-1.2.1.jar:./lib/commons-pool-1.3.jar" net.amsoft.iservice.asp.provisioning.server.iredirection.IRedirectionServer rmi://${BIND_IP}:${BIND_PORT}/IRedirectionServer ${ILINK_RMI_PORT} &
	sleep 3
    ;;
    stop)
		ps -ef | grep rmi | grep -v "grep" | awk -F" " '{ print $2; }' | xargs kill
    ;;
	*)
		echo "Usage: $0 {start|stop}"
		exit 1
	;;
esac
